﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/AdminCP/Views/Shared/ViewMasterPage1.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div class="content-box">
        <div class="content-box-header">
            <h3>
                Danh mục Quận Huyện</h3>
        </div>
        <!-- End .content-box-header -->
        <div class="content-box-content">
            <table id="list">
            </table>
            <div id="pager">
            </div>
            <script type="text/javascript">
                $(function () {
                    var grid = $("#list");
                    grid.jqGrid({
                        url: '<%= Url.Action("Get_List_District", "QuanLyHanhChinh",null) %>',
                        datatype: 'json',
                        mtype: 'POST',
                        colNames: [
                        '#',
                        'Tên Quận Huyện',
                        'Tên Tỉnh Thành',
                        'Tên Quốc Gia'
                    ],
                        colModel: [
                        //                        { name: 'MAQUOCGIA', index: 'MAQUOCGIA', width: 40, align: 'center', sortable: true, key: true, searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge']} },
                        //                        { name: 'Name', index: 'Name', width: 150, align: 'left', sortable: true, searchoptions: { sopt: ['cn','bw', 'bn', 'nc']} },
                        {name: 'MAQUANHUYEN', index: 'MAQUANHUYEN', width: 40, align: 'center', sortable: true, key: true, hidden: true },
                        { name: 'TENQUANHUYEN', index: 'TENQUANHUYEN', width: 150, align: 'left', sortable: true, searchoptions: { sopt: ['cn', 'bw', 'bn', 'nc']} },
                        { name: 'TENTINHTHANH', index: 'TENTINHTHANH', width: 150, align: 'left', sortable: false, search: false },
                        { name: 'TENQUOCGIA', index: 'TENQUOCGIA', width: 150, align: 'left', sortable: false, search: false }
                ],
                        jsonReader: {
                            root: "rows",
                            page: "page",
                            total: "total",
                            records: "records",
                            repeatitems: false,
                            userdata: "userdata"
                        },

                        multiselect: true,
                        multiboxonly: true,
                        rownumbers: true,
                        pager: $("#pager"),
                        toppager: true,
                        autowidth: true,
                        rowNum: 10,
                        rowList: [10, 15, 20, 30, 60],
                        sortname: 'TENQUANHUYEN',
                        sortorder: 'asc',
                        viewrecords: true,
                        height: 'auto',
                        caption: '',
                        beforeRequest: function () {
                            $('.jqgrid-overlay').fadeIn();
                        },
                        gridComplete: function () {
                            $('.jqgrid-overlay').fadeOut();
                        }
                    })
        .navGrid('#pager', { view: false, del: false, add: false, edit: false, searchtext: 'Tìm kiếm', cloneToTop: true },
                {}, // default settings for edit
                {}, // default settings for add
                {}, // delete instead that del:false we need this
                {closeOnEscape: true, multipleSearch: true, closeAfterSearch: true }, // search options
                {} /* view parameters*/
        );

                    grid.jqGrid('navGrid', '#ptoolbar', { del: false, add: false, edit: false, search: false });
                    grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });


                    grid.jqGrid('navButtonAdd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left"
                        caption: "",
                        title: "Thêm quận huyện",
                        buttonicon: 'ui-icon-plus',
                        onClickButton: function () {
                            window.location = '<%=Url.Action("AddDistrict", "QuanLyHanhChinh")%>';
                        }
                    });

                    grid.jqGrid('navButtonAdd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left"
                        caption: "",
                        buttonicon: 'ui-icon-pencil',
                        onClickButton: function () {
                            var selrows = grid.getGridParam("selarrrow");
                            if (selrows != null) {
                                if (selrows.length > 1) {
                                }
                                else if (selrows.length == 0) {
                                }
                                else {
                                    var url = '<%=Url.Action("EditDistrict", "QuanLyHanhChinh", new { id="ID" })%>';
                                    window.location = url.replace("ID", selrows);
                                }
                            }

                        }
                    });

                    grid.jqGrid('navButtonAdd', '#' + grid[0].id + '_toppager_left', { // "#list_toppager_left"
                        caption: "",
                        buttonicon: 'ui-icon-trash',
                        onClickButton: function () {
                            var selrows = grid.getGridParam("selarrrow");
                            var rows = "";

                            for (var i = 0; i < selrows.length; i++) {
                                if (selrows[i] != null) {
                                    if (rows.length <= 0)
                                        rows += selrows[i];
                                    else
                                        rows += "," + selrows[i];
                                }
                            }

                            if (rows.length > 0) {
                                var comfirm = confirm('Do you want to delete?');
                                if (comfirm) {
                                    $.post('<%=Url.Action("DeleteDistrict", "QuanLyHanhChinh") %>', { id: rows },
                        function (data) {
                            $('#list').trigger("reloadGrid", function () {
                                data;
                            });
                        });
                                }
                            }
                            else {
                            }
                        }
                    });

                    // remove some double elements from one place which we not need double
                    var topPagerDiv = $('#' + grid[0].id + '_toppager')[0];         // "#list_toppager"
                    $("#edit_" + grid[0].id + "_top", topPagerDiv).remove();        // "#edit_list_top"
                    $("#del_" + grid[0].id + "_top", topPagerDiv).remove();         // "#del_list_top"
                    $("#search_" + grid[0].id + "_top", topPagerDiv).remove();      // "#search_list_top"
                    $("#refresh_" + grid[0].id + "_top", topPagerDiv).remove();     // "#refresh_list_top"
                    $("#" + grid[0].id + "_toppager_center", topPagerDiv).remove(); // "#list_toppager_center"
                    $(".ui-paging-info", topPagerDiv).remove();

                    var bottomPagerDiv = $("div#pager")[0];
                    $("#add_" + grid[0].id, bottomPagerDiv).remove();               // "#add_list"

                });
     
            </script>
        </div>
        <!-- End .content-box-content -->
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderCss" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderScript" runat="server">
</asp:Content>
